<template>
	<!-- 钻机信息查询 -->
	<view class="container">
		<empty-data tipText="没有配件信息" v-if="partsDatas.length === 0"></empty-data>
		<view v-else>
			<block v-for="(item,index) in partsDatas" :key="index">
				<view class="white-bg z-font-lg u-padding-40 z-b-r u-flex u-row-between u-margin-bottom-20">
					<view class="u-flex-1">
						<view>配件名称：{{item.parts_type}}</view>
						<view>配件价格：{{item.buy_price | $_formattingMoney}}</view>
						<view>购买地址：{{item.buy_address}}</view>
						<view>配件编号：{{item.parts_id}}</view>
						<view>购买时间：{{item.buy_date}}</view>
						<view>
							<u-collapse>
								<u-collapse-item title="购买票据">
									<view class="u-margin-bottom-20 u-margin-left-20" v-for="(path,ip) in item.parts_receipt" :key="ip">
										<image style="width: 100%;height: 200rpx;" :src="path" @click="previewImg(item.parts_receipt)"></image>
									</view>
								</u-collapse-item>
							</u-collapse>
						</view>
					</view>
					<view class="u-margin-right-10 u-margin-left-20" style="color: #2979ff;" @click="partsUpdate(item._id)"><u-icon name="edit-pen"></u-icon>编辑</view>
				</view>
			</block>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				partsDatas:[]
			}
		},
		onLoad() {
			this.getPartsData();
		},
		methods: {
			async getPartsData(){
				this.$loading("正在加载");
				let res = await this.$network({
					api:"main",
					data:{
						action:"disposeData/getPartsInfo"
					}
				})
				
				uni.hideLoading();
				if(res.status === 0){
					this.partsDatas = res.data;
				} else if(res.status === -1){
					this.$refs.uToast.show({
						title: '没有数据',
						type: 'warning',
					})
				}
			},
			partsUpdate(id){
				uni.navigateTo({
					url:`../pm-add-parts/pm-add-parts?partsID=${id}`
				})
			},
			previewImg(imgs){
				uni.previewImage({
				    urls: imgs
				});
			}
		}
	}
</script>

<style>

</style>
